using UnityEngine;

public class FPSCamera : MonoBehaviour
{
	public Vector3 ThirdViewOffset = new Vector3(1f, 0f, -2f);

	public Vector3 FreeViewOffset = new Vector3(0f, 0f, -10f);

	public float ThirdViewZoomMult = 1f;

	public int ThirdViewInvert = 1;

	public Camera MainCamera;

	public ItemSticker FPSItemView;

	public Transform RayPointer;

	[HideInInspector]
	public float HorizonSway = 0.4f;

	public float VerticalSway = 0.4f;

	public Vector3 aimOffset;

	public bool IsThirdView;

	public bool IsFreeView;

	public bool zooming;

	public bool hideWhenScoping;

	private Vector3 swayOffset;

	private Vector3 positionTmpOffset;

	private Vector3 rootDirTmp;

	private Vector3 fpsDirTmp;

	private float rootDirHDot;

	private float rootDirVDot;

	private Vector3 rootDifPos;

	private bool isThirdViewTmp;

	private void Start()
	{
		positionTmpOffset = FPSItemView.transform.localPosition;
	}

	public void Aim(Vector3 offset)
	{
		aimOffset = offset;
	}

	public void Zoom()
	{
	}

	private void Update()
	{
		if (FPSItemView == null)
		{
			return;
		}
		if ((IsThirdView && !zooming) || (IsThirdView && zooming && !hideWhenScoping))
		{
			Vector3 b = new Vector3(ThirdViewOffset.x * (float)ThirdViewInvert, ThirdViewOffset.y, ThirdViewOffset.z * ThirdViewZoomMult);
			Vector3 b2 = new Vector3(FreeViewOffset.x * (float)ThirdViewInvert, FreeViewOffset.y, FreeViewOffset.z);
			if (IsThirdView)
			{
				float maxDistance = Vector3.Distance(base.transform.position, MainCamera.transform.position);
				RaycastHit[] array = Physics.RaycastAll(base.transform.position + base.transform.right * ThirdViewOffset.x * ThirdViewInvert, -base.transform.forward, maxDistance);
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].collider != null && array[i].collider.transform.root != base.transform.root)
					{
						MainCamera.transform.position = array[i].point;
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					MainCamera.transform.localPosition = Vector3.Lerp(MainCamera.transform.localPosition, b, Time.deltaTime * 30f);
				}
				FPSItemView.transform.localScale = Vector3.zero;
			}
			if (IsFreeView)
			{
				MainCamera.transform.localPosition = Vector3.Lerp(MainCamera.transform.localPosition, b2, Time.deltaTime * 30f);
				FPSItemView.transform.localScale = Vector3.zero;
			}
		}
		else
		{
			MainCamera.transform.localPosition = Vector3.zero;
			FPSItemView.transform.localScale = Vector3.one;
			RayPointer.forward = base.transform.forward;
		}
		if (isThirdViewTmp != IsThirdView)
		{
			base.gameObject.transform.root.gameObject.SendMessageUpwards("OnViewChanged", SendMessageOptions.DontRequireReceiver);
			isThirdViewTmp = IsThirdView;
		}
		float b3 = Vector3.Dot(base.gameObject.transform.root.transform.right.normalized, rootDirTmp.normalized) * HorizonSway;
		float b4 = Vector3.Dot(base.transform.up.normalized, fpsDirTmp.normalized) * VerticalSway;
		if (aimOffset != Vector3.zero)
		{
			b3 = 0f;
			b4 = 0f;
		}
		rootDirHDot = Mathf.Lerp(rootDirHDot, b3, 10f * Time.deltaTime);
		rootDirVDot = Mathf.Lerp(rootDirVDot, b4, 10f * Time.deltaTime);
		swayOffset.x = rootDirHDot;
		swayOffset.y = rootDirVDot;
		Vector3 b5 = positionTmpOffset + -swayOffset + aimOffset;
		FPSItemView.transform.localPosition = Vector3.Lerp(FPSItemView.transform.localPosition, b5, 5f * Time.deltaTime);
		rootDirTmp = base.gameObject.transform.root.transform.forward;
		fpsDirTmp = base.transform.forward;
	}
}
